#include "../include/SearchEngineServer.h"
#include <iostream>
#include <signal.h>

SearchEngineServer *g_server = nullptr;

void signalHandler(int signum)
{
    std::cout << "\n🛑 接收到信号 " << signum << ", 正在关闭服务器..." << std::endl;
    if (g_server)
    {
        g_server->stop();
    }
    exit(0);
}

int main()
{
    // 注册信号处理
    signal(SIGINT, signalHandler);
    signal(SIGTERM, signalHandler);

    std::cout << "🚀 搜索引擎服务器启动中..." << std::endl;

    try
    {
        g_server = SearchEngineServer::getInstance();
        g_server->start();
    }
    catch (const std::exception &e)
    {
        std::cerr << "💥 服务器启动失败: " << e.what() << std::endl;
        return -1;
    }

    return 0;
}